"""
Diagnostic script for review_service initialization

Checks if review_service can be properly initialized
"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

from dotenv import load_dotenv
load_dotenv()

import logging

# Set up logging to see all messages
logging.basicConfig(
    level=logging.DEBUG,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)

print("=" * 70)
print("Review Service Initialization Diagnostic")
print("=" * 70)

print("\n1. Attempting to import review_service...")
try:
    from src.services.review_service import review_service, HiAgentClient, load_config
    print("   [SUCCESS] review_service imported")
    print(f"   HiAgentClient available: {HiAgentClient is not None}")
    print(f"   load_config available: {load_config is not None}")
except Exception as e:
    print(f"   [FAILED] Could not import review_service: {e}")
    import traceback
    traceback.print_exc()
    sys.exit(1)

print("\n2. Checking review_service initialization...")
print(f"   Is initialized: {review_service.is_initialized()}")

if not review_service.is_initialized():
    error = review_service.get_initialization_error()
    print(f"   Initialization error: {error}")
    print("\n[FAILED] review_service not properly initialized")
    sys.exit(1)
else:
    print(f"   Config base URL: {review_service.config.base_url}")
    print(f"   Config app key: {review_service.config.app_key[:10]}...")
    print("\n[SUCCESS] review_service is properly initialized!")

print("\n3. Testing simple_review method...")
try:
    success, result, error = review_service.simple_review(
        user_id="diagnostic_test",
        question="What is 2+2?",
        grading_criteria="Answer should be correct",
        student_answer="2+2 equals 4",
        student_answer_file=None,
        document_name="test.txt"
    )

    if success:
        print(f"   [SUCCESS] Review completed!")
        print(f"   Review ID: {result.review_id}")
    else:
        print(f"   [FAILED] Review failed: {error}")

except Exception as e:
    print(f"   [FAILED] Exception: {e}")
    import traceback
    traceback.print_exc()

print("\n" + "=" * 70)
print("Diagnostic Complete")
print("=" * 70)
